package com.management.controller;


import com.management.controller.form.*;
import com.management.service.DefectRecordService;
import com.management.utils.OSSTemplate;
import com.management.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙世超
 * @since 2022-03-23
 */
@RestController
@Api(tags = "缺陷相关操作")
@RequestMapping("/defectRecord")
public class DefectRecordController {

    @Resource
    private DefectRecordService defectRecordService;

    /**
     * 获取所有项目
     * @return
     */
    @ApiOperation("获取所有项目")
    @GetMapping("/GetAllproject")
    public Result GetAllproject(){
        return defectRecordService.FindAllProject();
    }

    /**
     * 获取所有缺陷
     * @return
     */
    @ApiOperation("获取所有缺陷")
    @GetMapping("/GetAllDefect")
    public Result GetAllDefect(){
        return defectRecordService.FindAllDefect();
    }


    /**
     * 新建缺陷
     * @param defectProject
     * @return
     * @throws IOException
     */
    @ApiOperation("新建缺陷")
    @PostMapping("/createdefectproject")
    public Result CreateDefectProject(@RequestBody @Valid CreateDefectProjectForm defectProject) throws IOException {
        return defectRecordService.AddDefectProject(defectProject);
    }

    /**
     * 获取缺陷表中的所有数据
     * @param getRecordsPageForm
     * @return
     */
    @ApiOperation("获取缺陷表中的所有数据")
    @PostMapping("/GetAllDefectRecords")
    public Result GetAllDefectRecords(@RequestBody GetRecordsPageForm getRecordsPageForm){
        return defectRecordService.FindAllDefectRecords(getRecordsPageForm);
    }

    /**
     * 根据登录用户的ID获取其被指派的缺陷
     * @param getRecordsPageForm
     * @return
     */
    @ApiOperation("根据登录用户的ID获取其被指派的缺陷")
    @PostMapping("/GetDefectRecordsByaccountId")
    public Result GetDefectRecordsByaccountId(@RequestBody GetRecordsPageForm getRecordsPageForm){
        return defectRecordService.FindDefectRecordsByaccountId(getRecordsPageForm);
    }

    /**
     * 获取缺陷表中的所有项目
     * @return
     */
    @ApiOperation("获取缺陷表中的所有项目")
    @GetMapping("/GetAllDefectProject")
    public Result GetAllDefectProject(){
        return defectRecordService.FindAllDefectProject();
    }

    /**
     * 根据缺陷ID获取该项目缺陷
     * @param projectByIdForm
     * @return
     */
    @ApiOperation("根据缺陷ID获取该项目缺陷")
    @PostMapping("/GetDefectProjectById")
    public Result GetDefectProjectById(@RequestBody GetDefectProjectByIdForm projectByIdForm){
        return defectRecordService.FindDefectProjectById(projectByIdForm);
    }

    /**
     * 逻辑删除某项目缺陷
     * @param projectByIdForm
     * @return
     */
    @ApiOperation("逻辑删除某项目缺陷")
    @PostMapping("/DeleteRecordById")
    public Result DeleteRecordById(@RequestBody GetDefectProjectByIdForm projectByIdForm){
        return defectRecordService.DeleteRecordById(projectByIdForm);
    }

    /**
     * 批量删除项目缺陷
     * @param deleteRecordsForm
     * @return
     */
    @ApiOperation("批量删除项目缺陷")
    @PostMapping("/deleteRecords")
    public Result deleteRecords(@RequestBody deleteRecordsForm deleteRecordsForm){
        return defectRecordService.deleteRecords(deleteRecordsForm);
    }

    /**
     * 根据缺陷ID获取项目缺陷
     * @param projectByIdForm
     * @return
     */
    @ApiOperation("根据缺陷ID获取项目缺陷")
    @PostMapping("/editById")
    public Result editById(@RequestBody GetDefectProjectByIdForm projectByIdForm){
        return defectRecordService.editById(projectByIdForm);
    }

    /**
     * 根据缺陷ID修改项目缺陷
     * @param editByIdForm
     * @return
     */
    @ApiOperation("根据缺陷ID修改项目缺陷")
    @PostMapping("/changeRecord")
    public Result changeRecord(@RequestBody EditByIdForm editByIdForm){
        return defectRecordService.changeRecord(editByIdForm);
    }

    /**
     * 获取该项目下的工作人员
     * @param projectName
     * @return
     */
    @ApiOperation("获取该项目下的工作人员")
    @GetMapping("/Getassignee")
    public Result Getassignee(String projectName){
        return defectRecordService.Findassignee(projectName);
    }

    /**
     * 改变该缺陷被指派的人员
     * @param changeassignForm
     * @return
     */
    @ApiOperation("改变该缺陷被指派的人员")
    @PostMapping("/changeassignee")
    public Result changeassignee(@RequestBody changeassignForm changeassignForm){
        return defectRecordService.changassignee(changeassignForm);
    }

    /**
     * 根据缺陷ID获取缺陷
     * @param projectByIdForm
     * @return
     */
    @ApiOperation("根据缺陷ID获取缺陷")
    @PostMapping("/HandleRecordById")
    public Result HandleRecordById(@RequestBody GetDefectProjectByIdForm projectByIdForm){
        return defectRecordService.FindRecordById(projectByIdForm);
    }

    /**
     * 保存缺陷处理
     * @param saveHandleForm
     * @return
     */
    @ApiOperation("保存缺陷处理")
    @PostMapping("/saveHandle")
    public Result saveHandle(@RequestBody SaveHandleForm saveHandleForm){
        return defectRecordService.SaveHandle(saveHandleForm);
    }

    /**
     * 根据条件查询缺陷状态占比
     * @param getStateCountForm
     * @return
     */
    @ApiOperation("根据条件查询缺陷状态占比")
    @PostMapping("getStateCount")
    public Result getStateCount(@RequestBody GetStateCountForm getStateCountForm){
        Result stateCount = defectRecordService.getStateCount(getStateCountForm);
        return stateCount;
    }

    /**
     * 获取所有缺陷分类占比
     * @return
     */
    @GetMapping("getAllTypeCount")
    public Result getAllTypeCount(){
        Result allTypeCount = defectRecordService.getAllTypeCount();
        return allTypeCount;
    }

    /**
     * 根据条件查询缺陷分类占比
     * @param getStateCountForm 条件参数
     * @return
     */
    @ApiOperation("根据条件查询缺陷分类占比")
    @PostMapping("getTypeCount")
    public Result getTypeCount(@RequestBody GetStateCountForm getStateCountForm){
        Result typeCount = defectRecordService.getTypeCount(getStateCountForm);
        return typeCount;
    }

    /**
     * 获取所有严重程度占比
     * @return
     */
    @ApiOperation("获取所有严重程度占比")
    @GetMapping("getAllSeverityCount")
    public Result getAllSeverityCount(){
        Result allSeverityCount = defectRecordService.getAllSeverityCount();
        return allSeverityCount;
    }

    /**
     * 根据条件获取严重程度占比
     * @param getSeverityCountForm 条件参数
     * @return
     */
    @ApiOperation("根据条件获取严重程度占比")
    @PostMapping("getSeverityCount")
    public Result getSeverityCount(@RequestBody GetSeverityCountForm getSeverityCountForm){
        Result severityCount = defectRecordService.getSeverityCount(getSeverityCountForm);
        return severityCount;
    }
}

